package model 
{
	import model.macro.Player;
	import model.macro.Territory;
	import model.macro.Unit;
	import model.micro.Battle;
	/**
	 * Battle artifacts for battle history
	 * @author John
	 */
	public class BattleReport 
	{
		static public const SURRENDER_BY_DEFENDER:String = "Surrender by defender"; // Case where defending units stay and surrender
		static public const RETREAT_BY_DEFENDER:String = "Retreat by defender"; // Case where defending units must retreat
		static public const RETREAT_BY_ATTACKER:String = "Retreat by attacker"; // Case where attacking units must retreat
		
		private var _win_condition:String;
		private var _winner:Player;
		private var _loser:Player;
		private var _dead_attackers:Vector.<Unit>;
		private var _dead_defenders:Vector.<Unit>;
		private var _retreatingUnits:Vector.<Unit>; // Always the loser's units
		private var _remainingUnits:Vector.<Unit>; // Always the winners units
		private var _battle_territory:Territory;
		private var _invading_territory:Territory;
		
		public function BattleReport(winner:int, win_condition:String, battle_territory:Territory, invading_territory:Territory, attackers:Vector.<Unit>, defenders:Vector.<Unit>) 
		{
			if (winner == Battle.ATTACK_TEAM)
				_winner = invading_territory.owner;
			else
				_winner = battle_territory.owner;

			_win_condition = BattleReport.RETREAT_BY_DEFENDER;
			_battle_territory = battle_territory;
			_invading_territory = invading_territory;
			
			if (win_condition == RETREAT_BY_DEFENDER)
			{
				trace("retreat by defender. Units remaining: " + attackers.length);
				_remainingUnits = attackers;
				_retreatingUnits = defenders;
			}
			
			_dead_attackers = new Vector.<Unit>;
			_dead_defenders = new Vector.<Unit>;
			for each (var unit:Unit in attackers)
			{
				if (unit.dead)
					_dead_attackers.push(unit);
			}
			
			for each (unit in defenders)
			{
				if (unit.dead)
					_dead_defenders.push(unit);
			}
		}
		
		public function get win_condition():String 
		{
			return _win_condition;
		}
		
		public function get winner():Player 
		{
			return _winner;
		}
		
		public function get loser():Player 
		{
			return _loser;
		}
		
		public function get dead_attackers():Vector.<Unit> 
		{
			return _dead_attackers;
		}
		
		public function get dead_defenders():Vector.<Unit> 
		{
			return _dead_defenders;
		}
		
		public function get retreatingUnits():Vector.<Unit> 
		{
			return _retreatingUnits;
		}
		
		public function get remainingUnits():Vector.<Unit> 
		{
			return _remainingUnits;
		}
		
		public function get battle_territory():Territory 
		{
			return _battle_territory;
		}
		
		public function get invading_territory():Territory 
		{
			return _invading_territory;
		}
	}

}